package com.ruoyi.event.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.event.domain.bo.EventQdBo;
import com.ruoyi.event.domain.vo.EventQdVo;
import com.ruoyi.event.service.IEventQdService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 签到
 *
 * @author strongme
 * @date 2023-02-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/event/qd")
public class EventQdController extends BaseController {

    private final IEventQdService iEventQdService;

    /**
     * 查询签到列表
     */
    @GetMapping("/list")
    public TableDataInfo<EventQdVo> list(EventQdBo bo, PageQuery pageQuery) {
        return iEventQdService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询签到列表
     *
     * @return
     */
    @PostMapping("query")
    public R<List<EventQdVo>> query(@RequestBody EventQdBo eventQdBo) {
        return R.ok(iEventQdService.queryList(eventQdBo));
    }

    /**
     * 导出签到列表
     */
    @Log(title = "签到", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EventQdBo bo, HttpServletResponse response) {
        List<EventQdVo> list = iEventQdService.queryList(bo);
        ExcelUtil.exportExcel(list, "签到", EventQdVo.class, response);
    }

    /**
     * 获取签到详细信息
     *
     * @param qdId 主键
     */
    @GetMapping("/{qdId}")
    public R<EventQdVo> getInfo(@NotNull(message = "主键不能为空")
                                @PathVariable Long qdId) {
        return R.ok(iEventQdService.queryById(qdId));
    }

    /**
     * 新增签到
     */
    @Log(title = "签到", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EventQdBo bo) {
        return toAjax(iEventQdService.insertByBo(bo));
    }

    /**
     * 修改签到
     */
    @Log(title = "签到", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EventQdBo bo) {
        return toAjax(iEventQdService.updateByBo(bo));
    }

    /**
     * 删除签到
     *
     * @param qdIds 主键串
     */
    @Log(title = "签到", businessType = BusinessType.DELETE)
    @DeleteMapping("/{qdIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] qdIds) {
        return toAjax(iEventQdService.deleteWithValidByIds(Arrays.asList(qdIds), true));
    }
}
